package com.songdehuai.motherandchild;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

    ViewPager mainVp;

    TabLayout tabLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }


    void init() {
        tabLayout = findViewById(R.id.tabs);
        mainVp = findViewById(R.id.main_vp);
        ViewPagerAdapter viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
        viewPagerAdapter.addFrag(new ListFragment(), "第一个");
        viewPagerAdapter.addFrag(new ListFragment(), "第二个");
        viewPagerAdapter.addFrag(new ListFragment(), "第三个");
        viewPagerAdapter.addFrag(new ListFragment(), "第四个");
        mainVp.setAdapter(viewPagerAdapter);
        tabLayout.setupWithViewPager(mainVp);

    }

}
